package n1192;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {

	static class Point{
		int x,y;
		int weight;
	}
	
	static int N;
	
	static Point[] arr=new Point[1001];
	
	static List<Integer> child[]=new ArrayList[1001];
	
	static int max=Integer.MIN_VALUE;
	
	static boolean visit[]=new boolean[1001];
	
	static int dfs(int i)
	{
		visit[i]=true;
		int tmp=arr[i].weight;
		for(int j:child[i])
		{
			if(!visit[j])
			{
				int sub=dfs(j);
				if(sub>0)tmp+=sub;
			}
		}
		if(max<tmp)max=tmp;
		return tmp;
	}
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{

		BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
		N=Integer.parseInt(bf.readLine());
		for(int i=0;i<N;i++)
		{
			StringTokenizer st=new StringTokenizer(bf.readLine());
			int x=Integer.parseInt(st.nextToken());
			int y=Integer.parseInt(st.nextToken());
			int weight=Integer.parseInt(st.nextToken());
			Point p=new Point();
			p.x=x;
			p.y=y;
			p.weight=weight;
			arr[i]=p;
		}
		
		//初始化树结构
		for(int i=0;i<N;i++)child[i]=new ArrayList<Integer>();
		
		for(int i=0;i<N-1;i++)
		{
			for(int j=i+1;j<N;j++)
			{
				if(Math.abs(arr[i].x-arr[j].x)+Math.abs(arr[i].y-arr[j].y)==1)
				{
					child[i].add(j);
					child[j].add(i);
				}
			}
		}
		
		dfs(0);
		
		System.out.println(max);
		
		
	}

}
